#pragma once
#include "RamdomNum.h"
#include <random>
#include <stdio.h>

struct fNode {
	unsigned short m_leftValue;
	unsigned short m_rightValue;
	char m_type;
};

struct MouseCard {
	struct fNode* pNodeArray;
	int m_size;
	char m_type;
};

class CaculateAbstarct {
public:
	virtual void show() = 0;
	virtual void showRight() = 0;
	virtual void showWrong() = 0;
	virtual bool judge(short ans) = 0;
	virtual bool equal(unsigned short v1, unsigned short v2) = 0;
	virtual fNode* createFNode() = 0;
	CaculateAbstarct();
	unsigned short m_leftValue;
	unsigned short m_rightValue;
	char m_type;
};

class Add :public CaculateAbstarct {
public:
	Add() {
		RamdomNum* pR = RamdomNum::getInstance();
		unsigned short v1 = pR->getRamdomNum() % 101;
		unsigned short v2 = pR->getRamdomNum() % 101;
		while (!equal(v1, v2)) {
			v1 = pR->getRamdomNum() % 101;
			v2 = pR->getRamdomNum() % 101;
		}
		m_leftValue = v1;
		m_rightValue = v2;
		m_type = '+';
	}
	Add(unsigned short m_leftValue, unsigned short m_rightValue) {
		this->m_leftValue = m_leftValue;
		this->m_rightValue = m_rightValue;
		m_type = '+';
	}
	void show() {
		printf("%2d + %2d = ", m_leftValue, m_rightValue);
	}
	void showRight() {
		printf("\033[32;40m%2d + %2d =\033[0m ", m_leftValue, m_rightValue);
	}
	void showWrong() {
		printf("\033[31;40m%2d + %2d =\033[0m ", m_leftValue, m_rightValue);
	}
	bool judge(short ans) {
		if (m_rightValue + m_leftValue == ans)
			return true;
		return false;
	}
	fNode* createFNode() {
		fNode* fnode = new fNode;
		fnode->m_leftValue = this->m_leftValue;
		fnode->m_rightValue = this->m_rightValue;
		fnode->m_type = '+';
		return fnode;
	}
private:
	bool equal(unsigned short v1, unsigned short v2) {
		if (v1 + v2 >= 0 && v1 + v2 <= 100)
			return true;
		return false;
	}
};

class Sub :public CaculateAbstarct {
public:
	Sub() {
		RamdomNum* pR = RamdomNum::getInstance();
		unsigned short v1 = pR->getRamdomNum() % 101;
		unsigned short v2 = pR->getRamdomNum() % 101;
		while (!equal(v1, v2)) {
			v1 = pR->getRamdomNum() % 101;
			v2 = pR->getRamdomNum() % 101;
		}
		m_leftValue = v1;
		m_rightValue = v2;
		m_type = '+';
	}
	Sub(unsigned short m_leftValue, unsigned short m_rightValue) {
		this->m_leftValue = m_leftValue;
		this->m_rightValue = m_rightValue;
		m_type = '-';
	}
	void show() {
		printf("%2d - %2d = ", m_leftValue, m_rightValue);
	}
	void showRight() {
		printf("\033[32;40m%2d - %2d =\033[0m ", m_leftValue, m_rightValue);
	}
	void showWrong() {
		printf("\033[31;40m%2d - %2d =\033[0m ", m_leftValue, m_rightValue);
	}
	bool judge(short ans) {
		if (m_leftValue - m_rightValue == ans)
			return true;
		return false;
	}
	fNode* createFNode() {
		fNode* fnode = new fNode;
		fnode->m_leftValue = this->m_leftValue;
		fnode->m_rightValue = this->m_rightValue;
		fnode->m_type = '-';
		return fnode;
	}
private:
	bool equal(unsigned short v1, unsigned short v2) {
		if (v1 - v2 >= 0 && v1 - v2 <= 100)
			return true;
		return false;
	}
};